package com.example.lcpharmacy.controller;

import com.example.lcpharmacy.entity.GoodsCategoryEntity;
import com.example.lcpharmacy.lcutils.Pagination;
import com.example.lcpharmacy.mapper.GoodsCategoryDao;
import com.example.lcpharmacy.service.GoodsCategoryService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/goodsCategory")
public class GoodsCategoryImpl {

    @Autowired
    GoodsCategoryDao goodsCategoryDao;

    @Autowired
    GoodsCategoryService goodsCategoryService;


    @RequestMapping("/getCategory")
    public PageInfo getCategory(@RequestBody Pagination pagination) {
        PageInfo<GoodsCategoryEntity> goodsCategoryPageInfo = goodsCategoryService.goodsCategoryPage(pagination.getPageNum(), pagination.getPageSize());
        return goodsCategoryPageInfo;
    }

    @RequestMapping("/deleteCategory")
    public int deleteCategory(@RequestBody GoodsCategoryEntity goodsCategoryEntity) {
        int i = goodsCategoryDao.deleteByCode(goodsCategoryEntity.getCategoryCode());
        return i;
    }

    @RequestMapping("/updateCategory")
    public String updateCategory(@RequestBody GoodsCategoryEntity goodsCategoryEntity) {
        String result  = goodsCategoryService.updateCategory(goodsCategoryEntity);
        return result;
    }

    @RequestMapping("/insertCategory")
    public String insertCategory(@RequestBody GoodsCategoryEntity goodsCategoryEntity) {
        String result  = goodsCategoryService.insertCategory(goodsCategoryEntity);
        return result;
    }
}
